
var rowIdRet = "";
var sex ="";
var status="";
var rowOpenId = "";
var rowName = "";
var hInfo = "";
$(function(e){
	dataInit();
});

function dataInit(){
	eventInit();
	$('#messageTable').bootstrapTable({
		url: path+'f519cbb772e1456895d8448652367628', method: 'post', striped: true, cache: false, pagination: true,
        contentType: "application/x-www-form-urlencoded", sidePagination: "server", pageSize: 10, uniqueId: "id", detailView: false,
        queryParams: function (params) {
        	return { limit: params.limit, offset: params.offset,searchParams:$("#searchParams").val()};
        },//传递参数（*）
        columns:[{field: 'Number', title: '序号', align: 'center', width: '50', formatter: function (value, row, index) {
        			return index+1;
        		}}, 
        		{field: 'familyName', title: '用户姓名', align: 'center', width: '150', formatter: function (value, row, index) {
        			if(isNull(value)){
	            		value = '-';
	            	}
        			return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }},
	            {field: 'familySex', title: '性别', align: 'center', width: '150', formatter: function (value, row, index) {
	            	if(isNull(value)){
	            		value = '-';
	            	}
	         
	            	return '<a style="word-wrap:break-word;">'+value+'</a>';
	            	
	            }},
	            
	            {field: 'familyStatus', title: '用户身份', align: 'center', width: '150', formatter: function (value, row, index) {
	            	if(isNull(value)){
	            		value = '-';
	            	}
	            	return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }}, 
        		{field: 'familyPhone', title: '手机号', align: 'center', width: '150', formatter: function (value, row, index) {
        			if(isNull(value)){
	            		value = '-';
	            	}
        			return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }},
	            {field: 'hInfo', title: '房间信息', align: 'center', width: '150', formatter: function (value, row, index) {
	            	if(isNull(value)){
	            		value = '-';
	            	}
	            	return '<a style="word-wrap:break-word;">'+value+'</a>';
	            }},
	            {field: 'familyType', title: '审核状态', align: 'center', width: '150', formatter: function (value, row, index) {
	            	if(isNull(value)){
	            		value = '-';
	            	}else{
	            		if(value == "未审核"){
	            			return '<a style="word-wrap:break-word;color:blue">未审核</a>';
	            		}if(value == "审核通过"){
	            			return '<a style="word-wrap:break-word;color:green">审核通过</a>';
	            		}if(value == "审核失败"){
	            			return '<a style="word-wrap:break-word;color:red">审核失败</a>';
	            		}
	            	}
	            }},
	            
	            {field: 'operate', title: '操作', align: 'center', width: '210', events: {
	            	 'click .RoleOfA': function (e, value, row, index) {
	            		 hInfo = row.hInfo;
	            		 editFamilyType(row.id);
		                },
		                'click .RoleOfB': function (e, value, row, index) {
		                	qiao.bs.confirm("确定要删除此项吗？",function(){
		                		deleteFamily(row.id);
			                },function(){});
		                },
	            },
	            formatter: function (value, row, index) {
	            	return [
						'<button type="button" class="RoleOfA btn btn-default  btn-sm" style="margin-right:15px;">审核</button>',
						'<button type="button" class="RoleOfB btn btn-default  btn-sm" style="margin-right:15px;">删除</button>',

	        	        ].join('');
	            }
        }],
        onLoadSuccess: function(data){  //加载成功时执行
        	if(data.returnCode!=0){
        		qiao.bs.msg({msg:data.returnMessage,type:'danger'});
        	}
        }
    });
	
	//修改审核状态
	$('#updateFamilyTypeForm').bootstrapValidator({
        fields: {
        	updatefamilyType: {validators: {notEmpty: {message: '审核状态不能为空'}}},
        },
        submitHandler: function (validator, form, submitButton) {
        	var params = null;
    			params = {
					rowId:rowIdRet,
					familyType:$("#updatefamilyType").val(),
    				openId : rowOpenId,
    				familyName : rowName,
    				hInfo :  hInfo
    			};
    		AjaxPostUtil.request({url:path+"5c4e6f19ce2c4f7d86f840e26850fe0a",params:params,type:'json',callback:function(json){
    			if(json.returnCode==0){
    				qiao.bs.msg({msg:"保存成功",type:'success'});
    				$("#updateFamilyTypeMention").modal("hide");
    				$('#messageTable').bootstrapTable('refresh',{url:path+'f519cbb772e1456895d8448652367628'});
    			}else{
    				qiao.bs.msg({msg:json.returnMessage,type:'danger'});
    			}
    		}});
    		return false;
        }
    });
	
	//删除
	function deleteFamily(rowId){
		AjaxPostUtil.request({url:path+"a6d95f5715e042adb71177ceca748c25",params:{rowId:rowId},type:'json',callback:function(json){
			if(json.returnCode==0){
				qiao.bs.msg({msg:"删除成功",type:'success'});
				$('#messageTable').bootstrapTable('refresh',{url:path+'f519cbb772e1456895d8448652367628'});
			}else{
				qiao.bs.msg({msg:json.returnMessage,type:'danger'});
			}
		}});
	}
}

function editFamilyType(rowId){
	AjaxPostUtil.request({url:path+"4876f4024f5149e5b648adfea751022f",params:{rowId:rowId},type:'json',callback:function(json){
		console.log(json)
		if(json.returnCode==0){
			    rowIdRet = json.bean.id;
			    rowOpenId = json.bean.openId;
			    rowName = json.bean.familyName;
				$("#updatefamilyType").val(json.bean.familyType);
				$("#updateFamilyTypeMention").modal("show");
		}else{
				qiao.bs.msg({msg:json.returnMessage,type:'danger'});
			}
	}});
		
}

function eventInit(){
	
	$('body').on('click', '#addFamily', function(e){
		location.href = "../../html/wechat_signup/signup.html";
	});	
	
	//回车模糊搜索
	$('body').keydown(function() {
        if (event.keyCode == "13") {//keyCode=13是回车键
        	var params = {
        			limit : 10,
        			offset : 0,
        			searchParams : $("#searchParams").val()
        	}
        	AjaxPostUtil.request({url : path+"f519cbb772e1456895d8448652367628", params : params, type : 'json', callback : function(json){
        		if(json.returnCode == 0){
        			console.log(json);
        			$('#messageTable').bootstrapTable('refresh',{url : path+'f519cbb772e1456895d8448652367628'});
        		}else{
        			qiao.bs.msg({msg : '参数错误.', type : 'danger'});
        		}
        	}});
        }
	});
	
	//刷新表单
	$('body').on('click', '#refreshDiv', function(e){
		$('#messageTable').bootstrapTable('refresh',{url : path+'f519cbb772e1456895d8448652367628'});
		qiao.bs.msg({msg : "刷新成功.", type : 'success'});
	});
	
}

